<?php
/*####################
# PHP Kod koj sto gi naoga vo baza gradovite sto 
# zapocnuvaat so tekovno baraniot string 
# i mu gi vraka na korisnikot kako predlog
####################*/

require_once('includes/inc.php');
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
$str=trim($_GET['str']);
$len=trim($_GET['len']);

$pattern = "/[0'?;\/#&_+]/";
if (preg_match($pattern,$str)) $errval=1;
else $errval=0;

if(!$errval)
{
$rez="";
$connector = new DbConnector();
$qu="SELECT grad FROM predlozi WHERE grad LIKE '".$str."%'";
$result = $connector->query($qu);
while($row = $connector->fetchArray($result))
{
	$del1=substr($row['grad'],0,$len);
	$del2=substr($row['grad'],$len,strlen($row['grad']));
	$rez.="<div class=\"suggitem\" id=\"".$row['grad']."\" name=\"suggitem\" onclick=\"smeni('".$row['grad']."')\"><b>".$del1."</b>".$del2."</div>";
}

echo $rez;
}
else echo "";
?>